
<template>
  <div>
    <transition name="LtoR">
      <div class="loginBox absolute fixedCenter" style="height:510px;" v-show="whoShow==3">
        <Icon type="ios-arrow-back" class="absolute f_26 cCCC textLink" @click="sendFa(1)" style="top:10px;left:0;"/>
        <Logo title="忘记密码"/>

        <Input type="number"  placeholder="请输入手机号" @on-change="ttxT" 
        onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))"
        v-model="mobile"  ref="mobile" class="marginB20 " clearable size="large"	>
          <!-- <Icon type="ios-call" slot="prefix" /> -->
        </Input>
        
        <Row class=" marginB20 " :gutter="20">
          <Col span="16">
            <Input type="text"  placeholder="图形验证码" v-model="captcha" ref="captcha"  clearable size="large">
              <!-- <Icon type="ios-options" slot="prefix" /> -->
            </Input>
          </Col>
          <Col span="8">
            <img :src="tchaObj.img" class="width100 pointer" height="36" @click="$parent.tchaFun">
          </Col>
        </Row>
        <Row class=" marginB20 " :gutter="20">
          <Col span="16">
            <Input type="number"  placeholder="短信验证码" v-model="code" ref="code"  clearable size="large"
              onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))"
            >
              <!-- <Icon type="ios-chatboxes" slot="prefix" /> -->
            </Input>
          </Col>
          <Col span="8">
          <!-- button 倒计时函数，要用jq处理，原因细说 -->
            <Button type="primary" size="large" long @click="goCodeFun"  :disabled="btnDisabled" id="bDom"
          >获取验证码</Button>
          </Col>
        </Row>
        
        <Input type="password" v-model="password" placeholder="请输入 不低于6位数密码" ref="password" class="marginB20" size="large" clearable>
          <!-- <Icon type="md-lock" slot="prefix" /> -->
        </Input>
        <Input type="password" v-model="passwordAG" placeholder="再次确认密码" ref="passwordAG" class="marginB20" size="large" clearable>
          <!-- <Icon type="md-lock" slot="prefix" /> -->
        </Input>
        
        <Button type="primary"  class="btnGo" size="large" long @click="goFun" >确 定</Button>
      </div>
    </transition>
  </div>
</template>



<script>
import Logo from './_logo';//logo
export default {
  components: {
    Logo
  },
  data () {
    let data={
      mobile:'',
      password:'',
      passwordAG:'',

      phoneOk:true,//手机：false不能登录 ，true可以登录

      
      captcha:'',//图形 验证码
      code:'',//手机 验证码

      // 获取验证码按钮
      btnDisabled:false
    };
    return data;
  },
  //父=》子，接收父亲的值； 1账号密码/2手机短信/3忘记密码/4新用户注册
  props:['whoShow','tchaObj'],
  mounted(){
  },
  methods: {
    sendFa(num){
      //自定义方法往父传值
      this.$emit('getChildData',num);
    },
    //失去焦点判断
    ttxT(){
      let that=this;
      $app.ttxT(2,that);//type：1注册用；2登录+修改密码用
    },
    goCodeFun(){
      let that=this;
      $app.loginGetCodeFun(that,3,'bDom');//1注册,2登录,3修改密码,4合伙人认证,5绑定邮箱
    },
    //提交
    goFun () {
      let that=this;
      let {mobile,password,passwordAG,code,phoneOk}=that;
      
      if(!$app.telCheck(mobile)){
        that.$Message.error({content:'请输入正确的手机格式，勿含空格等特殊字符'});
        that.$refs['mobile'].focus();
      }else if(!phoneOk){
        that.$Message.error({ content: '该手机号未注册' });
        that.$refs['mobile'].focus();
      }else if(!$app.judgeData(code)){
        that.$Message.error({content:'验证码不能为空'});
        that.$refs['code'].focus();
      }else if(!$app.judgeData(password)){
        that.$Message.error({content:'密码不能为空'});
        that.$refs['password'].focus();
      }else if(password.length<6){
        that.$Message.error({content:'密码不能小于6位数'});
        that.$refs['password'].focus();
      }else if(passwordAG!=password){
        that.$Message.error({content:'请再次确认密码'});
        that.$refs['passwordAG'].focus();
      }else{
        $ajax.updatePwd(1,mobile,password,code,that,()=>{
          //初始化所有
          that.mobile='';
          that.password='';
          that.passwordAG='';
          that.captcha='';
          that.code='';

          that.sendFa(1);//回去登录页
        });
      }
    }
  }
}
</script>

<style>

</style>
